package common;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FSUtils
{
	public static File createFile(String path, String name) throws IOException
	{
		File outputFile = new File(path + File.separator + name);
		File folderDir = outputFile.getParentFile();
		if (!folderDir.exists())
			folderDir.mkdirs();
		if (!outputFile.exists())
			outputFile.createNewFile();
		return outputFile;
	}

	public static List<File> getFileInDirWithExt(String path, String ext)
	{
		File dir = new File(path);
		File[] files = dir.listFiles((pathname) -> {
			var n = pathname.getPath().split("\\.");
			var e = n[n.length - 1];
			return e.equals(ext);
		});
		List<File> list = new ArrayList<>();
		if (files != null)
			list.addAll(Arrays.asList(files));
		return list;
	}
}
